package com.zhuiyun.project.api.articlereport.mapper;

import com.zhuiyun.project.api.articlereport.model.ReportModel;
import com.zhuiyun.project.api.dict.entity.DictData;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * @ClassName ReportMapper
 * @Description TODO
 * @Author 韩佳轩
 * @Date 2023/6/15 10:35
 **/
@Mapper
public interface ReportMapper {

    /**
     * @Author 韩佳轩
     * @Description 全查举报文章
     * @Date 2023/6/16 14:47
     * @Return java.util.List<com.zhuiyun.project.api.articlereport.model.ReportModel>
     * @param reportModel
     */
//
//    @Select("<script>SELECT u.user_name as appUserName,ap.doctor_name as doctorName,ar.*,s.user_name as sysUserName,article.article_content " +
//            "from app_physician ap,article_report ar,app_user u,sys_user s,article " +
//            "where ar.reporting_user_id=u.id and ar.reported_user_id=ap.id and ar.processor_id=s.id and article.id=ar.id"+
//            "<when test='reportType!=&quot;&quot; and reportType!=null'>" +
//            "and ar.report_type like concat('%',#{reportType},'%') </when> and ar.del_flag=0</script>")
    @Select("<script>SELECT * FROM article_report  WHERE del_flag = 0 " +
            "<when test='reportType!=&quot;&quot; and reportType!=null'>" +
            "and article_report.report_type like concat('%',#{reportType},'%') </when> ORDER BY report_time desc</script>")
    List<ReportModel> reportAll(ReportModel reportModel);

    /**
     * @Author 韩佳轩
     * @Description 同意举报
     * @Date 2023/6/16 14:47
     * @Return
     * @param
     */

    @Update("update article_report set processing_result=1,report_status=1,update_time=now(),processing_time=now(),processor_name= #{processorName},rejection_reason=#{rejectionReason} where id=#{id}")
    int updateAgree(int id,String processorName,String rejectionReason);
    /**
     * @Author 韩佳轩
     * @Description 驳回举报
     * @Date 2023/6/16 14:48
     * @Return
     * @param
     */
    @Update("update article_report set processing_result=2,report_status=1,update_time=now(),processing_time=now(),processor_name= #{processorName} where id=#{id}")
    int updateReject(ReportModel reportModel);

    /**
    * @Author 韩佳轩
    * @Description app提交举报
    * @Date 2023/6/26 9:49
    * @Return
    * @param reportModel
    */
    @Insert("insert into article_report(reporting_user_id,reporting_user_name,reported_user_name,reported_user_id,report_type,report_conent,report_details,report_time,report_status,processing_time,processing_result,rejection_reason,processor_name,create_time,update_time,del_flag,report_id) " +
            "values(#{reportingUserId},#{reportingUserName},#{reportedUserName},#{reportedUserId},#{reportType},#{reportConent},#{reportDetails},#{reportTime},#{reportStatus},#{processingTime},#{processingResult},#{rejectionReason},#{processorName},#{createTime},#{updateTime},#{delFlag},#{reportId})")
    int addReport(ReportModel reportModel);

    /**
    * @Author 韩佳轩
    * @Description 根据字典管理全查举报类型
    * @Date 2023/6/28 20:43
    * @Return
    * @param dictData
    */
    @Select("select * from sys_dict_data where dict_id=5")
    List<DictData> getReportType(DictData dictData);

}
